package cn.wolfcode.mp.controller;

import cn.wolfcode.mp.domain.Employee;
import cn.wolfcode.mp.service.IEmployeeService;
import cn.wolfcode.mp.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 前后端分离项目: restful 接口--返回的数据都是json格式
 */
@RestController
@RequestMapping("emps")
public class EmployeeController {

    @Autowired
    private IEmployeeService employeeService;

    //接口开发
    @GetMapping("/list")
    public Object list(){
        return employeeService.list();
    }

    @GetMapping("/detail")
    public Object detail(Long id){
        return employeeService.getById(id);
    }

    @PostMapping("/saveOrUpdate")
    public Object saveOrUpdate(Employee employee){

       /*  if (employee.getId() == null){
            employeeService.save(employee);
        }else {
            employeeService.saveOrUpdate(employee);
        }
        */

        employeeService.saveOrUpdate(employee);
        return JsonResult.success();
    }
}
